package model

import (
	"gorm.io/gorm"
	__ "petCombo-srv/proto"
)

type Combo struct {
	gorm.Model
	Title  string
	Name   string  `gorm:"type:varchar(20)" json:"name"`
	TypeId int     `gorm:"type:int" json:"type_id"`
	Price  float64 `gorm:"type:decimal(10,2)" json:"price"`
}

func (c *Combo) ComboList(db *gorm.DB, comboId int) []*__.ComboList {

	var combos []*__.ComboList

	query := db.Model(c)

	if comboId != 0 {
		query = query.Where("id = ?", comboId)
	}

	err := query.Find(&combos).Error
	if err != nil {
		panic(err)
	}
	return combos

}
